# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - configure with --enable-high-precision for v6/v7 to fix stack corruption
#  - patch to fix enabling high precision
#  - patch to fix FTBFS on ARM

pkgname=sbc
pkgver=1.5
pkgrel=2
pkgdesc="Bluetooth Subband Codec (SBC) library"
url="https://git.kernel.org/pub/scm/bluetooth/sbc.git"
arch=(x86_64)
license=(GPL LGPL)
depends=(glibc)
makedepends=(git)
provides=(libsbc.so)
_commit=b2c20a3ecf5ed00f63c94077a9762b505935ede9  # tags/1.5^0
source=("git+$url#commit=$_commit"
        0001-Add-config.h-in-sbc-sbc_primitives.h.patch
        0002-Fix-build-on-ARM.patch)
sha512sums=('SKIP'
            '5daaffdf735b6fa8d3526b02cccbb378aa91c72a6f093824164d335f80a72448285835666226ef5fcecc2fc802b1bf44cb34356bfe4e90b944a5b128373a9f52'
            'ffe8736c3efb51833eddd983a23ca924c2bf6071f59ff391e253c184469995a399d762ee05e826fb8a83f697c5698e8551e779c3d86a23238647df304a0d43f1')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/-/+/g'
}

prepare() {
  cd $pkgname
  patch -p1 -i ../0001-Add-config.h-in-sbc-sbc_primitives.h.patch
  patch -p1 -i ../0002-Fix-build-on-ARM.patch
  autoreconf -fvi
}

build() {
  cd $pkgname
  [[ $CARCH == "armv6h" || $CARCH == "armv7h" ]] && CONFIG="--enable-high-precision"
  ./configure --prefix=/usr --disable-static --disable-tester $CONFIG
  make
}

check() {
  cd $pkgname
  make check
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install
}
